package com;


public class Permutations {

	// print N! permutation of the characters of the string s (in order)
	public static void perm1(String s) {
		perm1("", s);
	}

	private static void perm1(String prefix, String s) {
		int N = s.length();
		if (N == 0)
			System.out.println(prefix);
		else {
			for (int i = 0; i < N; i++)
				perm1(prefix + s.charAt(i),
						s.substring(0, i) + s.substring(i + 1, N));
		}

	}

	// print N! permutation of the elements of array a (not in order)
	public static void perm2(String s) {
		int N = s.length();
		char[] a = new char[N];
		for (int i = 0; i < N; i++)
			a[i] = s.charAt(i);
		perm2(a, N);
	}

	private static void perm2(char[] a, int n) {
		if (n == 1) {
			double result = 0;
			for (int i = 0; i < digs.length - 1; i++) {
				if(i == 0){
					result = Operate(digs[i], digs[i + 1], a[i]);
				}else{
					result = Operate(result, digs[i + 1], a[i]);
				}
			}
			//if(result == 13){
				
				//System.out.println(Arrays.toString(digs));
				//System.out.print(a);
				System.out.print("=");
				for (int i = 0; i < digs.length-1; i++) {
					System.out.print(digs[i]);
					System.out.print(a[i]);
				}
				System.out.println(digs[digs.length-1]);
				//System.out.println(":"+result);
			//}
			return;
		}
		for (int i = 0; i < n; i++) {
			swap(a, i, n - 1);
			perm2(a, n - 1);
			swap(a, i, n - 1);
		}
	}

	private static double Operate(double i, int j, char a) {
		if ('+' == a) {
			return i+j;
		} else if ('-' == a) {
			return i-j;
		} else if ('*' == a) {
			return i*j;
		} else if ('/' == a) {
			return i/j;
		}else{
			return 0;
		}
	}

	// swap the characters at indices i and j
	private static void swap(char[] a, int i, int j) {
		char c;
		c = a[i];
		a[i] = a[j];
		a[j] = c;
	}

	static int[] digs = new int[] { 6, 3, 5, 7, 4, 8 };
	static String ops = "+-*/+";

	public static void main(String[] args) {
		int N = Integer.parseInt("5");
		String elements = ops.substring(0, N);
		// perm1(elements);
		System.out.println();
		perm2(elements);// no order

	}
}
